﻿#region 命名空间

using System;
using System.Web;
using System.Configuration;
using System.Collections.Generic;
using System.Configuration.Provider;
using System.Configuration.Internal;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// Web.config的属性
    /// </summary>
    public static class WebConfig
    {
        /// <summary>
        /// 网站域名
        /// </summary>
        public static string DomainName
        {
            get { return ConfigurationManager.AppSettings["DomainName"]; }
            set
            {
                var co = new ConfigurationOperator();
                co.SetAppSetting("DomainName", value);
                co.Save();
            }
        }

        /// <summary>
        /// 虚拟目录
        /// </summary>
        public static string VirtualPath
        {
            get { return ConfigurationManager.AppSettings["VirtualPath"]; }
            set
            {
                var co = new ConfigurationOperator();
                co.SetAppSetting("VirtualPath", value);
                co.Save();
            }
        }

        /// <summary>
        /// 网站名字
        /// </summary>
        public static string SiteName
        {
            get { return ConfigurationManager.AppSettings["SiteName"]; }
            set
            {
                var co = new ConfigurationOperator();
                co.SetAppSetting("SiteName", value);
                co.Save();
            }
        }

        /// <summary>
        /// 网站后台目录
        /// </summary>
        public static string BackGroundPath
        {
            get { return ConfigurationManager.AppSettings["BackGroundPath"]; }
            set
            {
                var co = new ConfigurationOperator();
                co.SetAppSetting("BackGroundPath", value);
                co.Save();
            }
        }


        /// <summary>
        /// 数据库链接
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                var cs = ConfigurationManager.GetSection("dataConfiguration") as DatabaseSettings;

                return ConfigurationManager.ConnectionStrings[cs.DefaultDatabase].ConnectionString;
            }
            set
            {
                var co = new ConfigurationOperator();
                co.SetConnectionString("ConnectionString", value);
                co.Save();
            }
        }
    }
}